package Business;

import Message.Tips;
import java.io.*;

public class FileIO {

    /**
     * 复制文件
     * @param source 源文件
     * @param target 目标文件
     */
    public static boolean copyFile(File source , File target){
        InputStream inputStream = null;
        OutputStream outputStream = null;
        try {
            inputStream = new FileInputStream(source.toString());
            outputStream = new FileOutputStream(target.toString());
            byte[] buf = new byte[1024];
            int read;
            while ((read = inputStream.read(buf)) != -1){
                outputStream.write(buf , 0 , read);
            }
        } catch (IOException e) {
            e.printStackTrace();
            Tips.Warm("复制文件异常！" + source + " ===>>> " + target);
            return false;
        } finally {
            if (inputStream != null){
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (outputStream != null){
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return true;
    }

}
